function form_block (block) {
    var id = block.id;
    var content = block.content;
    var create_time = cut_until(block.create_time, '.');
    var modify_time = cut_until(block.modify_time, '.');
    var str = '<li id="'+ id +'_block-item" class="block-item with-shadow"><div class="block-item-wrapper">'
    +'<div class="block-item-drag-handler">'
        +'<div class="block-item-inner">'
            +'<div class="block-item-meta">Create:<span class="create-time">'+ create_time+'</span> | Modify:<span class="modify-time">'+modify_time+'</span></div>'
            +'<div class="block-item-fold-btn float-left"></div>'
            +'<div id="'+id +'_block-item-content" class="block-item-content">' + content + '</div>'
            +'<div class="block-item-brief" style="display:none;">' + cut_content(content, 40) + '</div>'
            +'<div class="block-item-properties">'
                +'<div class="block-item-ctrl"> '
                    +'<span class="small-btn-base ic16-remove">'
                        +'<a href="#" class="small-btn-hlight block-item-remove-btn" title="Remove Me."></a>'
                    +'</span>'
                    +'<span class="small-btn-base ic16-moveto">'
                        +'<a href="#" class="small-btn-hlight block-item-moveto-btn" title="Move to ..."></a>'
                    +'</span>'
                    +'<span class="small-btn-base ic16-cite">'
                        +'<a href="#" class="small-btn-hlight block-item-cite-btn" title="Copy citation information."></a>'
                    +'</span>'
                    +'<span class="small-btn-base ic16-edit">'
                        +'<a href="#" class="small-btn-hlight block-item-edit-btn" title="Edit Me"></a>'
                    +'</span>'
                    +'<span class="small-btn-base ic16-pin">'
                        +'<a href="#" class="small-btn-hlight block-item-pin-btn" title="Pin Me"></a>'
                    +'</span>'

                +'</div> '
                +'<div class="block-item-tag-bar"><span class="float-left">Tags:</span>'
                    +'<span class="ic16-tag small-btn-base ">'

                        +'<a href="#" class="small-btn-hlight block-item-tag-btn" title="Add/Edit tags for this note."></a>'
                    +'</span>'
                +'</div>'
                +'<div class="float-fix"></div>  '
            +'</div>'
        +'</div></div></div></li>';
    return str;
}

function form_note (id, title) {
    var str =  '<div id="'+ id + '_note-item" class="note-item">'
          + '<div class="note-item-btns">'
                +'<span class="small-btn-base note-item-remove-btn-wrap">'
                    +'<a href="#" class="small-btn-hlight note-item-remove-btn" title="Remove this note."></a>'
                +'</span>'
          + '</div>'
          + '<a href="#" class="note-item-icon-wrap" ><img class="note-item-icon" alt="Computer" src="imgs/icons/64x64/note.png"/></a>'
          + '<div class="note-item-title">' + title 
          + '</div></div>';
    return str;
}

function form_note_view () {
    var str='<div class="content-view note-view-content note-view">'
        +   '<ul class="block-item-ul"></ul>'
        +   '</div>';
    return str;
}

function form_tab_btn(target_page, title) {
    var str='<li class="ui-corner-top">'
        + '<a href="#' 
        + target_page
        + '" class="tab-close-btn"></a>'
        + '<a href="#'
        + target_page
        + '" class="tab-label" >'
        + title
        + '</a>'
        + '</li>';
    return str;
}

function form_result (note_id, title, block_id, breif) {
    var str='<li id="'+note_id+'_'+block_id 
        + '" class="result-item"><h3 class="result-item-title"><a href="#">'+ title
        +   '</a></h3>'
        +   '<div class="result-item-content">'+breif+'</div>'
        +   '</li>';
    return str;
}

function cut_content(obj, len) {
    return $('<div>'+obj+'</div>').text().substr(0, len) + '...';
}

function cut_until(str, stop) {
    if (str){
        var idx = str.indexOf(stop);
        if (idx == -1)
            return str
        return str.substr(0, idx);
    } else {
        return '';
    }
}


function count2size (max, min, x) { 
    return 12 / (max_count-min_count) * x + (12-2*max_count/(max_count-min_count))
}

function get_formal_id (dom_id) {
    return $(dom_id).attr('id').toString().split('_')[0];
}

function get_formal_id_by_str (str) {
    return str.split('_')[0];
}

function trigger_citelink_click(obj) {
    var url = $(obj).attr('href');
    var cite_link = [];
    if (url.indexOf('cite://') != -1) {
        cite_link = url.substr(7).split('-');
    }
    if (cite_link.length != 2)
        return;
    var note_id = cite_link[0];
    var block_id = cite_link[1];
    ubi.notebook_view.open_note(note_id, block_id);
}

